package com.jason.kotlin.gank.repository

import com.jason.kotlin.gank.api.ApiSource
import com.jason.kotlin.gank.api.GankService
import com.jason.kotlin.gank.model.GankApiResponse
import com.jason.kotlin.gank.model.GankCategoryBean
import com.jason.kotlin.gank.model.GankDataBean


/**
 * Gank API接口的数据请求实现
 *
 * @property service GankService
 */
class GankApiImpl() : GankApi {

    private var service: GankService = ApiSource.getGankService(GankService::class.java)

    override suspend fun loadBanners() = service.loadBanners()

    override suspend fun loadWeekHotData(
        type: String,
        category: String,
        count: Int
    ): GankApiResponse<List<GankDataBean>> = service.loadWeekHotData(type, category, count)

    override suspend fun loadWeekHotGanHuoWithViews(): GankApiResponse<List<GankDataBean>> {
        return loadWeekHotData(GankService.HOT_TYPE_VIEWS, GankService.CATEGORY_GANHUO, 20)
    }

    override suspend fun loadCategoryData(
        category: String,
        type: String,
        page: Int,
        count: Int
    ) = service.loadCategoryData(category, type, page, count)

    override suspend fun loadGirlData(page: Int): GankApiResponse<List<GankDataBean>> {
        return loadCategoryData(GankService.CATEGORY_GIRL, GankService.TYPE_GIRL, page, 20)
    }

    override suspend fun getRandomData(
        category: String?,
        type: String?,
        count: Int
    ) = service.getRandomData(category, type, count)

    override suspend fun getCategoriesGanHuo(): GankApiResponse<List<GankCategoryBean>> =
        service.getCategories(GankService.CATEGORY_GANHUO)

    override suspend fun getCategoriesArticle(): GankApiResponse<List<GankCategoryBean>> =
        service.getCategories(GankService.CATEGORY_ARTICLE)


    override suspend fun getSearchData(
        keyword: String?,
        page: Int,
        count: Int
    ): GankApiResponse<List<GankDataBean>> = service.getSearchData(keyword, page, count)

    override suspend fun getArticleDetail(postId: String): GankApiResponse<List<GankDataBean>> =
        service.getArticleDetail(postId)
}